package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteLevelOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.LevelDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.LevelCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.service.LevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/admin/level")
public class AdminLevelController {

    @Autowired
    LevelService levelService;



    @PostMapping("")
    public Result addLevel(@RequestBody LevelCommand command){
        levelService.addLevel(command);

        return Result.ok();
    }

    @PutMapping("")
    public Result updateLevel(@RequestBody LevelCommand command){
        levelService.updateLevel(command);

        return Result.ok();
    }

    @GetMapping("/list")
    public Result<PageDTO<LevelDTO>> getLevelList(@Valid PageRequest request){
        PageDTO<LevelDTO> levels = levelService.getLevelList(request);

        return Result.ok(levels);
    }

    @DeleteMapping("/{id}")
    public Result<DeleteLevelOperateDTO> deleteLevel(@PathVariable Long id){

        return Result.ok(levelService.deleteLevel(id));
    }

    @DeleteMapping("/batch")
    public Result<List<DeleteLevelOperateDTO>> deleteLevels(@RequestBody BatchDeleteCommand command){
        levelService.deleteLevels(command);

        return Result.ok();
    }
}
